package com.sh.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.sh.dao.StudentDao;
import com.sh.entity.Student;
import com.sh.util.Result;

@RestController
public class StudentController {
	@Autowired
	private StudentDao studentDao;

	@RequestMapping("/selectStudent")
	public Result getAll(Integer limit, Integer page, Student student, Map<String, Object> map) {
		map.put("page", (page - 1) * limit);
		map.put("limit", limit);
		map.put("sName", student.getsName());
		map.put("sSex", student.getsSex()); // 存取页数和前台传来的数据
		List<Map<String, Object>> getAlList = studentDao.getAll(map);
		Integer getInteger = studentDao.getCount();
		Result result = new Result(true, 0, null, getInteger, getAlList);
		return result;
	}

	// 添加
	@RequestMapping("/insertStudent")
	public Result getadd(Student student) {
		int inserts = studentDao.insertStudent(student);
		Result res = new Result(200, "", inserts, true);
		return res;
	}

	// 修改
	@RequestMapping("/updateStudent")
	public Result updateStudent(Student student) {
		
		
		Integer updates = studentDao.updateStudent(student);
		
		
		Result res=new Result(0, "true", updates, true);
		return res;
	}

	// 删除
	@RequestMapping("/deleteStudent")
	public Result deleteTeacher(Integer sid) {
		int i = studentDao.deleteStudent(sid);
		Result res = new Result(200, "", i, true);
		return res;

	}

}
